//
//  YPAssetsViewController.m
//  ChengHuiTong
//
//  Created by KiVen on 15/11/2.
//  Copyright © 2015年 张文权. All rights reserved.
//

#import "YPAssetsViewController.h"
#import "YPMyInvestViewController.h"
#import "YPAccountDetailViewController.h"
#import "YPPayBackPlanViewController.h"
#import "YPCouponViewController.h"
#import "YPWebViewController.h"
#import "SelectView.h"
#import "HfAccountViewController.h"
#import "RxWebViewController.h"
#import "MyRedPacketViewController.h"
#import "YPAutoTenderViewController.h"
#import "YPRegistViewController.h"
#import "YPZQRecordViewController.h"
#import "UICountingLabel.h"
#import "YPStationMessageViewController.h"
#import <UIButton+WebCache.h>
#import "YPHSDepositoryView.h"

@interface YPAssetsViewController ()<UIScrollViewDelegate>{
    
    //账户总额
    UICountingLabel * _HFtotalAccountContentLabel;
    
    //累计赚取
    UILabel*_profitMoney;
    
    //可用余额
    UILabel*_canUseMoney;
    
    //资料字典
    NSDictionary*_infoDic;
    
    //待收总额
    UILabel*_collectMoney;
    
    //未登录背景视图
    UIView*_backGroundView;
    
    //头像按钮
    UIButton *_headBtn;
    
    //导航栏背景
    UIView * _navgationBar;
    
}
 //存管视图
@property (nonatomic,strong)YPHSDepositoryView *depositoryView;

@end

@implementation YPAssetsViewController

#pragma mark--生命周期

- (void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
    
}

- (instancetype)init{
    self = [super init];
    if (self) {
        
        [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(refreshNotifiAction) name:@"YPAssetsVCRefreshNofification" object:nil];
    }
    
    return self;
}

- (void)viewDidLoad {
    
    [super viewDidLoad];
    
    [self setupAssetsView];
    
}

-(void)viewWillAppear:(BOOL)animated{
    
    [super viewWillAppear:animated];
    
    [MobClick beginLogPageView:@"我的资产"];
    
    [self.navigationController setNavigationBarHidden:YES animated:YES];
    
    if ([YPShareAccountInfo shareAccountInfo].token) { //登录状态

        _backGroundView.hidden=YES;
        
        [self starRequest];

    }else{
        
        [_headBtn setImage:ImageNamed(@"xcl") forState:0];
        _profitMoney.text=@"0.00";
        _canUseMoney.text=@"0.00";
        _collectMoney.text=@"0.00";
        _HFtotalAccountContentLabel.text = @"0.00";
        _readView.hidden = YES;
        _backGroundView.hidden=NO;
        [self.depositoryView restore];
        
    }
    
}

- (void)viewWillDisappear:(BOOL)animated{
    
    [super viewWillDisappear:animated];
    
    [MobClick endLogPageView:@"我的资产"];
    
}

#pragma mark 网络请求
- (void)starRequest{
    
    [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
    [RequestModel  getMyAccountsuccessBlock:^(id obj) {
        [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];

        if ([obj[@"status"] intValue]==0) {
            
            _infoDic=(NSDictionary*)obj;
            
            _profitMoney.text=[NSString stringWithFormat:@"%@",obj[@"income"]];
            
            _canUseMoney.text=[NSString stringWithFormat:@"%@",obj[@"tmoney_usable"]];
            
            _collectMoney.text=[NSString stringWithFormat:@"%@",obj[@"money_wait"]];
            
            _HFtotalAccountContentLabel.text=[NSString stringWithFormat:@"%@",obj[@"tmoney"]];
            
            if(_HFtotalAccountContentLabel.text.doubleValue > 0)[_HFtotalAccountContentLabel countFrom:0.00 to:[obj[@"tmoney"] doubleValue]   withDuration:1.0f];
            
            [self.depositoryView updateSubViewsWithHsState:obj[@"hs_status"]
                                                 hsAccount:obj[@"hs_account"]
                                                hsCardBank:obj[@"hs_card_bank"]
                                            hsCardRealname:obj[@"hs_card_realname"]
                                              hsCardNumber:obj[@"hs_card_number"]];
            
            User.msg_unread_count = obj[@"msg_unread_count"];
            self.readView.hidden = User.msg_unread_count.integerValue > 0 ? NO : YES;
            [[NSNotificationCenter defaultCenter] postNotificationName:@"YPMoreVCRefreshNofification" object:nil];
            
            if (![User.avatar isEqualToString:obj[@"avatar"]]) {
                User.avatar = obj[@"avatar"];
                [User saveData];
            }
            [_headBtn sd_setImageWithURL:[NSURL URLWithString:[YPShareAccountInfo shareAccountInfo].avatar]  forState:0 placeholderImage:ImageNamed(@"xcl")];
        }
        
        NSLog(@"我的资产数据%@",obj);
        
        
    } failBlock:^(id obj) {
        
        [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
    }];
    
}

#pragma mark 事件响应
/**登录*/
-(void)goLogin{
    
    [self goToLoginVCWithCompleteBlock:^(NSString *token){
        
        NSLog(@"token:%@=====%@",token,TOKEN);
    }];
}

/**注册*/
- (void)goRegister{
    
    [self.navigationController pushViewController:[YPRegistViewController new] animated:YES];
}

/**个人中心*/
- (void)goProfile{
    
    YPMoreViewController *moreVC = [[YPMoreViewController alloc]init];
    [self.navigationController pushViewController:moreVC animated:YES];
    
}

/**查看详情*/
- (void)goAccountDetail{
    
    [self.navigationController pushViewController:[YPAccountDetailViewController new] animated:YES];
    
}

/**跳转客服*/
- (void)customerBtnClick{
    
    YPGoWebView(String_Connect(CMD_KEFU, @"&token", TOKEN), self.navigationController);
}

/**跳转站内信*/
- (void)messageBtnClick{
    
    [self.navigationController pushViewController:[YPStationMessageViewController new] animated:YES];
}

/**中间按钮群*/
- (void)rechargeAndWithdrawButtonClisck:(UIButton*)btn{
    
    switch (btn.tag) {
        case 1000:{ //我的投资

            YPMyInvestViewController*investVC=[[YPMyInvestViewController alloc] init];
            
            [self.navigationController pushViewController:investVC animated:YES];

        }
            
            break;
        case 1001:{ //回款明细
            
            YPPayBackPlanViewController*payBackVC=[[YPPayBackPlanViewController alloc] init];
            
            [self.navigationController pushViewController:payBackVC animated:YES];
        }
            
            break;
        case 1002:{//资金明细
            
            HfAccountViewController*hfAccountVC=[[HfAccountViewController alloc] initWithInforMation:_infoDic];
            
            [self.navigationController pushViewController:hfAccountVC animated:YES];
        }
            
            break;
        case 1003:{ //自动投标
            
            YPAutoTenderViewController *autoTenderVC = [[YPAutoTenderViewController alloc]init];
            
            autoTenderVC.trust=YES;
            
            [self.navigationController pushViewController:autoTenderVC animated:YES];
        }
            
            break;
        case 1004:{ //我的红包
            
            
            [self.navigationController pushViewController:[MyRedPacketViewController new] animated:YES];
            
        }
            
            break;
        case 1005:{ //加息劵
            
            [self.navigationController pushViewController:[YPCouponViewController new] animated:YES];
        }
            
            break;
        case 1006:{ //我的积分
            
            YPGoWebView(String_Connect(CMD_POINT_MALLS, @"&token=", TOKEN), self.navigationController);
        }
            
            break;
        case 1007:{ //债权转让
            
            [self.navigationController pushViewController:[YPZQRecordViewController new] animated:YES];
        }
            
            break;
            
        default:
            break;
    }
       
}

/**提现*/
- (void)cashBtnClick{
    
      YPGoWebView(String_Connect(CMD_CASH, @"&token=", TOKEN), self.navigationController);
}

/**充值*/
- (void)rechargeBtnClick{
    
      YPGoWebView(String_Connect(CMD_RECHARGE, @"&token=", TOKEN), self.navigationController);
}

/**
 刷新通知
 */
- (void)refreshNotifiAction{
    
    [self starRequest];
}

#pragma mark - 私有方法
-(void)creatUnLongView{
    
    _backGroundView=[[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
    _backGroundView.backgroundColor = [UIColor colorWithWhite:0. alpha:0.5];
    [self.view addSubview:_backGroundView];
    
    
    UIView *bottomView = [[UIView alloc]initWithFrame:CGRectMake(0, SCREEN_HEIGHT - 211, SCREEN_WIDTH, 210)];
    bottomView.backgroundColor = [UIColor whiteColor];
    [_backGroundView addSubview:bottomView];
    
    
    UIImage *image = [UIImage imageNamed:@"cehnghuitong"];
    UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake((SCREEN_WIDTH - 160)/2.f, 0, 160, image.size.height/image.size.width*160)];
    imageView.image = image;
    imageView.centerX = bottomView.centerX;
    [bottomView addSubview:imageView];
    
    CGFloat width = (SCREEN_WIDTH - autoScaleW(15)*2 - autoScaleW(20))/2.f;
    UIButton *loginBtn = [UIButton creatWithFrame:CGRectMake(autoScaleW(15), imageView.bottom + 8, width, 40)
                                             font:[UIFont systemFontOfSize:15]
                                             text:@"登录"
                                        textColor:kColor_AppNavColor
                                           action:@selector(goLogin)
                                           target:self];
    loginBtn.layer.borderWidth = 1.f;
    loginBtn.layer.borderColor = kColor_AppNavColor.CGColor;
    [bottomView addSubview:loginBtn];
    
    
    UIButton *registerBtn = [UIButton creatWithFrame:CGRectMake(loginBtn.right +autoScaleW(20), loginBtn.top, width, loginBtn.height)
                                             font:loginBtn.titleLabel.font
                                             text:@"注册"
                                        textColor:[UIColor whiteColor]
                                           action:@selector(goRegister)
                                           target:self];
    registerBtn.backgroundColor = kColor_AppNavColor;
    [bottomView addSubview:registerBtn];
    
    UILabel *footLabel = [AppTools getFootLabel];
    footLabel.top = registerBtn.bottom + 3;
    [bottomView addSubview:footLabel];
    

}

- (void)setupAssetsView{
    
    //最底层的scrollView
    UIScrollView *assetsScrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - 49)];
    assetsScrollView.backgroundColor = [UIColor whiteColor];
    assetsScrollView.delegate = self;
    [self.view addSubview:assetsScrollView];
    
    //资产数据视图
    UIImageView *assetsBgImageV = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, autoScaleH(240) + 20)];
    assetsBgImageV.image = ImageNamed(@"wdbj");
    [assetsScrollView addSubview:assetsBgImageV];
    
    //设置下拉所见的视图
    UIView * topBackGroundView = [[UIView alloc]initWithFrame:CGRectMake(0, -300, SCREEN_WIDTH, 300)];
    topBackGroundView.backgroundColor = UIColorFromString(@"#f96a36");
    [assetsScrollView addSubview:topBackGroundView];
    
    //设置上拉所见的视图
    _navgationBar = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 64)];
    _navgationBar.backgroundColor = UIColorFromString(@"#f96a36");
    _navgationBar.alpha = 0;
    [self.view addSubview:_navgationBar];
    
    //三个点视图
    UIView *pointV = [self pointViewWithPoint:CGPointMake(autoScaleW(15), 33)];
    [self.view addSubview:pointV];
    
    //用户头像
    _headBtn = [UIButton creatWithFrame:CGRectMake(autoScaleW(23), 24, 35, 35)
                                  image:[UIImage imageNamed:@"xcl"]
                                 action:@selector(goProfile)
                                 target:self];
    ViewBorderRadius(_headBtn, _headBtn.height/2.f, 1.5, UIColorFromString(@"#fab296"));
    [self.view addSubview:_headBtn];
    
    
    //查看详情
    UIButton *goDetailBtn = [UIButton creatWithFrame:CGRectMake((SCREEN_WIDTH - 60)/2.f, _headBtn.top, 60, _headBtn.height)
                                                font:[UIFont systemFontOfSize:autoScaleW(14)]
                                                text:@"详情 >>"
                                              action:@selector(goAccountDetail)
                                              target:self];
    [self.view addSubview:goDetailBtn];
    
    
    //客服
    UIButton *customerBtn = [UIButton creatWithFrame:CGRectMake(SCREEN_WIDTH - _headBtn.width*2 - autoScaleW(20), _headBtn.top, _headBtn.width, _headBtn.height)
                                               image:ImageNamed(@"wdkftb")
                                              action:@selector(customerBtnClick)
                                              target:self];
    [self.view addSubview:customerBtn];
    
    
    //站内信
    UIButton *messageBtn = [UIButton creatWithFrame:CGRectMake(customerBtn.right + autoScaleW(5), _headBtn.top, _headBtn.width, _headBtn.height)
                                               image:ImageNamed(@"wdznx")
                                              action:@selector(messageBtnClick)
                                              target:self];
    [self.view addSubview:messageBtn];
    
    //消息红点
    self.readView.left = messageBtn.width - 13;
    [messageBtn addSubview:self.readView];
    

    //账户总额
    UILabel * HFaccountTotalMoneyLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 20 + autoScaleH(57), SCREEN_WIDTH, autoScaleH(14))];
    HFaccountTotalMoneyLabel.textColor=[UIColor whiteColor];
    HFaccountTotalMoneyLabel.font = [UIFont systemFontOfSize:autoScaleW(14)];
    HFaccountTotalMoneyLabel.text = @"账户总额(元)";
    HFaccountTotalMoneyLabel.textAlignment=1;
    [assetsBgImageV addSubview:HFaccountTotalMoneyLabel];

    _HFtotalAccountContentLabel = [[UICountingLabel alloc]initWithFrame:CGRectMake(0, 20 + autoScaleH(80), SCREEN_WIDTH, autoScaleH(45))];
    _HFtotalAccountContentLabel.text=@"0.00";
    _HFtotalAccountContentLabel.textAlignment=1;
    _HFtotalAccountContentLabel.textColor=[UIColor whiteColor];
    _HFtotalAccountContentLabel.font = [UIFont fontWithName:@"DIN-Bold" size:autoScaleW(35)];
    //设置格式
    _HFtotalAccountContentLabel.format = @"%.2f";
    //设置分隔符样式
    _HFtotalAccountContentLabel.floatingPositiveFormat = @"###,##0.00";
    [assetsBgImageV addSubview:_HFtotalAccountContentLabel];
    
    
    //可用余额，代收金额，累计收益
    int titleLabelWith = SCREEN_WIDTH/3.0;
    NSArray * titleArray = @[ @"可用余额",@"待收金额",@"累计收益"];
    for (int i = 0; i < 3; i++) {

        UILabel * titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(i*titleLabelWith, 20 + autoScaleH(144), titleLabelWith, autoScaleH(12))];
        titleLabel.text = titleArray[i];
        titleLabel.font=[UIFont systemFontOfSize:autoScaleW(12)];
        titleLabel.textColor=[UIColor whiteColor];
        titleLabel.textAlignment = NSTextAlignmentCenter;
        [assetsBgImageV addSubview:titleLabel];
        
        
        if (i != 2) {
            UIView*line=[[UIView alloc] initWithFrame:CGRectMake(titleLabel.width - 1,7, 0.5, 25)];
            line.backgroundColor=[AppTools colorWithHexString:@"#e6e6e6"];
            [titleLabel addSubview:line];
        }

    }
    
    //可用余额
    _canUseMoney=[[UILabel alloc] initWithFrame:CGRectMake(0, 20 + autoScaleH(165), titleLabelWith, 18)];
    _canUseMoney.font=[UIFont systemFontOfSize:autoScaleW(14)];
    _canUseMoney.text=@"0.00";
    _canUseMoney.textColor=[UIColor whiteColor];
    _canUseMoney.textAlignment=1;
    [assetsBgImageV addSubview:_canUseMoney];
    
    //待收总额
    _collectMoney=[[UILabel alloc] initWithFrame:CGRectMake(_canUseMoney.right, _canUseMoney.top, _canUseMoney.width, _canUseMoney.height)];
    _collectMoney.textColor=[UIColor whiteColor];
    _collectMoney.font=[UIFont systemFontOfSize:14];
    _collectMoney.text=@"0.00";
    _collectMoney.textAlignment=1;
    [assetsBgImageV addSubview:_collectMoney];
    
    //累计收益
    _profitMoney=[[UILabel alloc] initWithFrame:CGRectMake(_collectMoney.right, _canUseMoney.top, _canUseMoney.width, _canUseMoney.height)];
    _profitMoney.textAlignment = NSTextAlignmentCenter;
    _profitMoney.font=[UIFont systemFontOfSize:14];
    _profitMoney.text=@"0.00";
    _profitMoney.textColor=[UIColor whiteColor];
    [assetsBgImageV addSubview:_profitMoney];
    
    //隔离层
    CGFloat middleSpace = autoScaleH(70);
    [assetsScrollView addLineWithFrame:CGRectMake(0, assetsBgImageV.bottom, SCREEN_WIDTH, middleSpace) color:kColor_AppBaseBackground];
    
    //添加阴影
    UIView *shawdowView = [[UIView alloc]initWithFrame:CGRectMake(self.depositoryView.left, self.depositoryView.top + autoScaleH(43), self.depositoryView.width, autoScaleH(61))];
    shawdowView.layer.shadowColor = [UIColor lightGrayColor].CGColor;
    shawdowView.layer.shadowRadius = 10.f;
    shawdowView.layer.shadowOpacity = 0.8;
    shawdowView.layer.shadowPath = [[UIBezierPath bezierPathWithRect:shawdowView.bounds] CGPath];
    [assetsScrollView addSubview:shawdowView];
    
    //存管视图
    [assetsScrollView addSubview:self.depositoryView];
    
    //资产按钮群
    NSArray *imageArr = @[@"wdtz",@"hkmx",@"zjmx",@"zdtb",@"wdhb",@"jxj",@"wdjf",@"zqzr"];
    NSArray * rechargeTitleArray = @[@"我的投资",@"回款明细",@"资金明细",@"自动投标",@"我的红包",@" 加息劵",@"我的积分",@"债权转让"];
    CGFloat width = SCREEN_WIDTH/2.f;
    CGFloat height = autoScaleH(76);
    
    for (int i = 0 ; i < rechargeTitleArray.count; i ++) {
        
        UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(i%2*width, assetsBgImageV.bottom + middleSpace + i/2*height, width, height)];
        btn.tag = 1000+i;
        [btn addTarget:self action:@selector(rechargeAndWithdrawButtonClisck:) forControlEvents:UIControlEventTouchUpInside];

        UIImage *image = [UIImage imageNamed:imageArr[i]];
        UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(autoScaleW(39), (btn.height - image.size.height)/2.f, image.size.width, image.size.height)];
        imageView.image = image;
        [btn addSubview:imageView];
        
        UILabel *label = [UILabel creatWithFrame:CGRectMake(imageView.right + autoScaleW(20), 0, 100, btn.height)
                                            font:[UIFont systemFontOfSize:autoScaleW(15)]
                                            text:rechargeTitleArray[i]
                                       textColor:UIColorFromString(@"#000000")
                                   textAlignment:0];
        [btn addSubview:label];
       
        [assetsScrollView addSubview:btn];
        

        if (i % 2 != 0) {
            
            [assetsScrollView addLineWithFrame:CGRectMake(imageView.left, btn.bottom, SCREEN_WIDTH - imageView.left*2, 0.5) color:colorWithRGB(220, 220, 220)];
            [assetsScrollView addLineWithFrame:CGRectMake(btn.left, btn.top + autoScaleH(25), 0.5, autoScaleH(30)) color:colorWithRGB(220, 220, 220)];
        }
        
        if(i == rechargeTitleArray.count - 1)
            assetsScrollView.contentSize = CGSizeMake(assetsScrollView.width, btn.bottom + autoScaleH(62));
    }
    
    //底部充值提现
    UIView *bottomView = [[UIView alloc]initWithFrame:CGRectMake(0, SCREEN_HEIGHT - 49 - autoScaleH(62), SCREEN_WIDTH, autoScaleH(62))];
    [bottomView addLineWithFrame:CGRectMake(0, 0, bottomView.width, 0.5) color:colorWithRGB(220, 220, 220)];
    bottomView.backgroundColor = [UIColor colorWithWhite:1 alpha:0.9];
    [self.view addSubview:bottomView];
    
    //提现
    UIButton *cashBtn = [UIButton creatWithFrame:CGRectMake(autoScaleW(40), autoScaleH(14), autoScaleW(101), autoScaleH(35))
                                            font:[UIFont systemFontOfSize:autoScaleW(16)]
                                            text:@"提现"
                                       textColor:colorWithRGB(255, 77, 77)
                                          action:@selector(cashBtnClick)
                                          target:self];
    ViewBorderRadius(cashBtn, cashBtn.height/2.f, 1, colorWithRGB(255, 77, 77));
    [cashBtn setBackgroundImage:[LGToolMethods createImageWithColor:kColor_AppNavColor] forState:UIControlStateHighlighted];
    [cashBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted];
    [bottomView addSubview:cashBtn];
    
    
    //充值
    UIButton *rechargeBtn = [UIButton creatWithFrame:CGRectMake(autoScaleW(235), cashBtn.top, cashBtn.width, cashBtn.height)
                                            font:[UIFont systemFontOfSize:autoScaleW(16)]
                                            text:@"充值"
                                          action:@selector(rechargeBtnClick)
                                          target:self];
    rechargeBtn.backgroundColor = UIColorFromString(@"#FF7733");
    ViewRadius(rechargeBtn, rechargeBtn.height/2.f);
    [bottomView addSubview:rechargeBtn];

    [self creatUnLongView];
}

- (UIStatusBarStyle)preferredStatusBarStyle{
    
    return UIStatusBarStyleLightContent;
    
}

- (UIView *)pointViewWithPoint:(CGPoint)point{
    
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(point.x, point.y, 4, 16)];
    view.backgroundColor = [UIColor clearColor];
    for (int i = 0; i < 3; i ++) {
        UIView *point = [[UIView alloc]initWithFrame:CGRectMake(0, 6*i, 4, 4)];
        point.layer.cornerRadius = point.height/2.f;
        point.backgroundColor = [UIColor whiteColor];
        point.layer.masksToBounds = YES;
        [view addSubview:point];
    }
    return view;
}

- (YPHSDepositoryView *)depositoryView{
    
    if (!_depositoryView) {
        _depositoryView = [[YPHSDepositoryView alloc]initWithFrame:CGRectMake(autoScaleW(15), 20 + autoScaleH(197), SCREEN_WIDTH - autoScaleW(15)*2, autoScaleH(104)) state:YPHSDepositoryViewInitial];
        
        WeakSelf
        [_depositoryView configActionsWithBindBlock:^{ //绑卡/修改
            
            YPGoWebView(String_Connect(CMD_DEPOSITORYBIND, @"&token=", TOKEN), weakSelf.navigationController);
        } openBlock:^{ //立即开通
            
            YPGoWebView(String_Connect(CMD_DEPOSITORY, @"&token=", TOKEN), weakSelf.navigationController);
        }];
    }
    
    return _depositoryView;
}

//消息红点
- (UIView *)readView{
    
    if (!_readView) {
        
        _readView = [[UIView alloc]initWithFrame:CGRectMake(0, 7, 6, 6)];
        _readView.layer.cornerRadius = _readView.height/2.f;
        _readView.layer.masksToBounds = YES;
        _readView.backgroundColor = [UIColor redColor];
        _readView.hidden = YES;
    }
    return _readView;
}

#pragma mark -- UIScrollViewDelegate
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    
    CGFloat totalOffset = scrollView.contentSize.height - scrollView.height;
    _navgationBar.alpha = scrollView.contentOffset.y/totalOffset/1.2;
    
}

@end
